package com.yerbamateprimer.advice.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.google.common.base.Preconditions;
import com.yerbamateprimer.advice.MultipleReceptorAdvice;
import com.yerbamateprimer.model.User;

/**
 * This class models an advice
 * to let all the users know
 * that the round will be paused.
 * 
 * @author Matias Liwski
 * @version 1.0
 */
public class RoundPausedAdvice implements MultipleReceptorAdvice {
	private static final long serialVersionUID = 5766283356449740758L;
	private List<User> receptors;

	/**
	 * @param receptors The list of receptors for this advice;
	 */
	public RoundPausedAdvice(List<User> receptors) {
		this.receptors = new ArrayList<User>();
		addAllAdviceReceptors(receptors);
	}

	/* (non-Javadoc)
	 * @see com.yerbamateprimer.advice.MultipleReceptorAdvice#addReceptor(com.yerbamateprimer.model.User)
	 */
	@Override
	public void addAdviceReceptor(User adviceReceptor) {
		Preconditions.checkArgument(adviceReceptor != null, "Couldn't add a null receptor to this advice.");
		this.receptors.add(adviceReceptor);
	}

	/* (non-Javadoc)
	 * @see com.yerbamateprimer.advice.MultipleReceptorAdvice#addAllAdviceReceptors(java.util.Collection)
	 */
	@Override
	public void addAllAdviceReceptors(Collection<User> adviceReceptors) {
		Preconditions.checkArgument(adviceReceptors != null && !adviceReceptors.isEmpty(), "Couldn't add invalid receptors (receptors=" + adviceReceptors + ").");
		this.receptors.addAll(adviceReceptors);
	}

	/**
	 * A safe copy of advice receptors.
	 * @see com.yerbamateprimer.advice.MultipleReceptorAdvice#getAdviceReceptors()
	 */
	@Override
	public List<User> getAdviceReceptors() {
		return new ArrayList<User>(this.receptors);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, false);
	}
}